package com.xique.park.bean.transform.web.garageLaneDev;

import com.xique.common.core.enums.SubDeviceModel;
import com.xique.common.core.utils.SecurityUtils;
import com.xique.park.bean.domain.ParkDeviceSub;
import com.xique.park.bean.domain.ParkLane;
import com.xique.park.bean.request.web.garageLaneDev.subdev.AddSubDevRequest;
import com.xique.park.bean.request.web.garageLaneDev.subdev.EditSubDevRequest;
import com.xique.park.bean.vo.web.garageLaneDeviceTree.TreeNodeSubDevVo;

import java.util.Date;

/**
 * SubDevTransform
 *
 * @author xique
 */
public class SubDevTransform {

    /**
     * 附加设备实体转化为Vo实体
     */
    public static TreeNodeSubDevVo transformNodeSubDevVo(ParkDeviceSub parkDeviceSub, ParkLane parkLane, String type) {
        TreeNodeSubDevVo treeSubDevVo = new TreeNodeSubDevVo();
        treeSubDevVo.setId(parkDeviceSub.getId());
        treeSubDevVo.setLaneId(parkLane.getId());
        treeSubDevVo.setLaneName(parkLane.getName());
        treeSubDevVo.setName(parkDeviceSub.getName());
        treeSubDevVo.setType(parkDeviceSub.getType());
        treeSubDevVo.setModel(parkDeviceSub.getModel());
        treeSubDevVo.setIp(parkDeviceSub.getIp());
        treeSubDevVo.setPort(parkDeviceSub.getPort());
        treeSubDevVo.setStatus(parkDeviceSub.getStatus());
        treeSubDevVo.setType(type);
        treeSubDevVo.setModel(parkDeviceSub.getModel());
        treeSubDevVo.setLaneNo(parkDeviceSub.getLaneNo());
        treeSubDevVo.setSecretKey(parkDeviceSub.getSecretKey());
        treeSubDevVo.setCreateTime(parkDeviceSub.getCreateTime());
        treeSubDevVo.setUpdateTime(parkDeviceSub.getUpdateTime());
        if ("etc".equals(type)) {
            treeSubDevVo.setEtcTest(parkDeviceSub.getEtcTest());
        }
        return treeSubDevVo;
    }

    /**
     * 添加附加设备request转化为parkDeviceNew实体
     */
    public static ParkDeviceSub transformAddSubDevRequest(AddSubDevRequest request) {
        ParkDeviceSub parkDeviceSub = new ParkDeviceSub();
        parkDeviceSub.setParkId(SecurityUtils.getParkId());
        parkDeviceSub.setStatus(request.getStatus());
        parkDeviceSub.setName(request.getName());
        parkDeviceSub.setLaneId(request.getLaneId());
        parkDeviceSub.setIp(request.getIp());
        parkDeviceSub.setModel(request.getModel());
        parkDeviceSub.setPort(request.getPort());
        parkDeviceSub.setType(request.getType());
        parkDeviceSub.setUpdateTime(new Date());
        parkDeviceSub.setUpdateUser(SecurityUtils.getUserId());
        parkDeviceSub.setLaneNo(request.getLaneNo());
        parkDeviceSub.setSecretKey(request.getSecretKey());
        parkDeviceSub.setEtcTest(request.getEtcTest());
        return parkDeviceSub;
    }

    /**
     * 编辑附加设备request转化为parkDeviceNew实体
     */
    public static ParkDeviceSub transformEditSubDevRequest(EditSubDevRequest request) {
        ParkDeviceSub parkDeviceSub = new ParkDeviceSub();
        parkDeviceSub.setId(request.getId());
        parkDeviceSub.setParkId(SecurityUtils.getParkId());
        parkDeviceSub.setStatus(request.getStatus());
        parkDeviceSub.setName(request.getName());
        parkDeviceSub.setLaneId(request.getLaneId());
        parkDeviceSub.setIp(request.getIp());
        parkDeviceSub.setModel(request.getModel());
        parkDeviceSub.setPort(request.getPort());
        parkDeviceSub.setType(request.getType());
        parkDeviceSub.setUpdateTime(new Date());
        parkDeviceSub.setUpdateUser(SecurityUtils.getUserId());
        parkDeviceSub.setLaneNo(request.getLaneNo());
        parkDeviceSub.setSecretKey(request.getSecretKey());
        parkDeviceSub.setEtcTest(request.getEtcTest());
        return parkDeviceSub;
    }
}
